#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 简单表单
from django import forms

class RegisterForms(forms.Form):

    username = forms.CharField(label='帐号', max_length=20)
    password = forms.CharField(label='密码', max_length=20, min_length=5,
                widget=forms.PasswordInput(attrs={'placeholder': '请输入密码',}),
                error_messages={
                    'min_length': '密码长度过小',
                    'max_length': '密码长度过长',
                })
    password_repeat = forms.CharField(label='再次输入密码', widget=forms.PasswordInput())
    email = forms.CharField(widget=forms.EmailInput)

    def clean(self):

        cleaned_data = super().clean()
        # 增加自定义的功能
        password = cleaned_data.get('password')
        password_re = cleaned_data.get('password_repeat')
        if password_re != password:
            self.add_error('password', '两次输入的密码不一致')